<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="标题">
        审核结果
      </el-form-item>
      <el-form-item label="内容">
        <el-input v-model="event.data.detail" :rows="10" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-radio v-model="checkResult" label="审核通过">通过</el-radio>
        <el-radio v-model="checkResult" label="审核不通过">不通过</el-radio>
      </el-form-item>
      <el-form-item>
        <el-button
          :disabled="saveBtnDisabled"
          type="primary"
          @click="checkCourse"
        >
          审核
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import messageApi from '@/api/message'
import courseApi from '@/api/edu/course'
export default {
  data() {
    return {
      checkResult: "审核通过",
      event: {
        topic: "system",
        userId: "0",
        entityType: 1,
        entityId: "1",
        entityUserId: "0",
        data: {
          courseId: "",
          courseName: "",
          title: "审核结果",
          detail: ""
        }
      },
      BASE_API: process.env.VUE_APP_BASE_API,
      saveBtnDisabled: false // 保存按钮是否禁用,
    }
  },

  //页面渲染成功
  created() {
    this.init()
  },

  methods: {
    init() {
      this.fetchCourseInfoById(this.$route.params.id)
    },
    fetchCourseInfoById(id) {
      courseApi.getCourseInfoById(id).then(response => {
        this.event.entityUserId = response.data.item.teacherId
        this.event.userId = response.data.item.teacherId
        this.event.data.courseId = response.data.item.id
        this.event.data.courseName = response.data.item.title
      })
    },
    // 新增数据
    checkCourse() {
      this.saveBtnDisabled = true
      courseApi.checkCourse(this.$route.params.id,this.checkResult).then(response => {
        // debugger
        messageApi.sendSysMsg(this.event).then(response => {
          this.$message({
            type: 'success',
            message: response.message
          })
          this.$router.push('/edu/course/list')
        })
      })
    },
  }
}
</script>
